{% extends '::base.html.twig' %}

{% block body %}

<div class="content">
    <div class="form-row row-fluid" id="div_form_devis">
        {% include "GdsVenteBundle::Devis/form_devis.html.twig" %}
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function() {
        $('#departement').val({{user.departement.id}})
        $('#gds_ventebundle_devistype_date').datepicker();
        $('#retour2').hide()
        var fullDate = new Date();
        var twoDigitMonth = fullDate.getMonth()
        twoDigitMonth++
        twoDigitMonth += "";
        if (twoDigitMonth.length == 1)
            twoDigitMonth = "0" + twoDigitMonth;
        var twoDigitDate = fullDate.getDate() + "";
        if (twoDigitDate.length == 1)
            twoDigitDate = "0" + twoDigitDate;
        var currentDate = twoDigitDate + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
        $("#gds_ventebundle_devistype_date").val(currentDate)
        setInterval(time, 1000);
        $('#form_devis').validate();
        $('#submit_form_devis').click(function() {
            $(this).hide()
            $('#submit_form_devis_print').hide()
            $('#gds_ventebundle_devistype_reference').focus()
            if ($('#form_devis').valid()) {
                $.ajax({
                    url: '{{path("gds_vente_devis")}}',
                    type: "POST",
                    datatype: 'json',
                    data: $('#form_devis').serialize() + '&articles={"articles":' + JSON.stringify(articles) + '}&heure=' + $('#heure').val(),
                    success: function(data) {
                        if (data.success) {
                            $.msgBox({
                                title: "Devis",
                                content: "Enregistrement Effectué avec succés",
                                type: "info",
                                buttons: [{value: "OK"}],
                                success: function(result) {
                                    location.reload();
                                }
                            });
                        } else {
                            $.msgBox({
                                title: "Devis",
                                content: "Erreur D'enregistrement",
                                type: "error",
                                buttons: [{value: "OK"}],
                                success: function(result) {
                                    $('#submit_form_devis').show("slow")
                                    $('#submit_form_devis_print').show("slow")
                                }
                            });
                        }
                    },
                    error: function(e) {
                        $.msgBox({
                            title: "Devis",
                            content: "Erreur D'enregistrement",
                            type: "error",
                            buttons: [{value: "OK"}],
                            success: function(result) {
                                $('#submit_form_devis').show("slow")
                                $('#submit_form_devis_print').show("slow")
                            }
                        });
                    }
                })
            }
        })
        $('#submit_form_devis_print').click(function() {
            $(this).hide()
            $('#submit_form_devis').hide()
            $('#gds_ventebundle_devistype_reference').focus()
            if ($('#form_devis').valid()) {
                $.ajax({
                    url: '{{path("gds_vente_devis")}}',
                    type: "POST",
                    datatype: 'json',
                    data: $('#form_devis').serialize() + '&articles={"articles":' + JSON.stringify(articles) + '}&heure=' + $('#heure').val(),
                    success: function(data) {
                        if (data.success) {
                            Imprimer(data.id)
                        } else {
                            $.msgBox({
                                title: "Devis",
                                content: "Erreur D'enregistrement",
                                type: "error",
                                buttons: [{value: "OK"}],
                                success: function(result) {
                                    $('#submit_form_devis').show("slow")
                                    $('#submit_form_devis_print').show("slow")
                                }
                            });
                        }
                    },
                    error: function(e) {
                        $.msgBox({
                            title: "Devis",
                            content: "Erreur D'enregistrement",
                            type: "error",
                            buttons: [{value: "OK"}],
                            success: function(result) {
                                $('#submit_form_devis').show("slow")
                                $('#submit_form_devis_print').show("slow")
                            }
                        });
                    }
                })
            }
        })
        Array.prototype.remove = function(v) {
            this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1);
        }
        index = 0;
        nb_article = 1;
        // var index_array = Array();
        articles = new Array();
        // On r�cup�re la balise <div> en question qui contient l'attribut � data-prototype � qui nous int�resse
        $container = $('#gds_ventebundle_lignedevistype');


    });


</script>

<input type="hidden" id="heure"/>
{% endblock %}    